package cn.wolfcode.web.controller;

import cn.wolfcode.common.exception.BusinessException;
import cn.wolfcode.common.web.CommonCodeMsg;
import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.SeckillProduct;
import cn.wolfcode.domain.SeckillProductVo;
import cn.wolfcode.service.ISeckillProductService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.apache.bcel.generic.RET;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/seckillProduct")
@Slf4j
public class SeckillProductController {
    @Autowired
    private ISeckillProductService seckillProductService;

    @RequestMapping("/queryAllCurrent")
    public Result<List<SeckillProductVo>> queryAllCurrent() {
        //1  验证参数
        //2 调用服务
        List<SeckillProductVo> ret = seckillProductService.queryAllCurrent();
        return Result.success(ret);
    }

    @GetMapping("/queryByTime")
    public Result<List<SeckillProductVo>> queryByTime(Integer time) {
        if (StringUtils.isEmpty(time)) {
            throw new BusinessException(CommonCodeMsg.PARAM_IS_EMPTY);
        }
        List<SeckillProductVo> list = seckillProductService.queryByTime(time);
        return Result.success(list);

    }

    @GetMapping("/find")
    public Result<SeckillProductVo> find(Integer time,Long seckillId) {
        if (StringUtils.isEmpty(time) || StringUtils.isEmpty(seckillId)) {
            throw new BusinessException(CommonCodeMsg.PARAM_IS_EMPTY);
        }
        SeckillProductVo seckillProductVo = seckillProductService.find(time,seckillId);
        return Result.success(seckillProductVo);

    }


}
